package com.example.cores_activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.cores_activity.utils.DateUtil;

public class ResponseActivity extends AppCompatActivity implements View.OnClickListener {

    static private String msg = "销毁证据，立即撤离";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_response);


        TextView tv_rec = findViewById(R.id.tv_rec);
        findViewById(R.id.btn_res).setOnClickListener(this);

        // 获取上一个页面传递的数据
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            String reqTime = bundle.getString("req_time");
            String reqContent = bundle.getString("req_content");
            String format = String.format("收到消息：%s\n时间：%s", reqContent, reqTime);
            tv_rec.setText(format);

            // 显示响应数据
            TextView tv_res = findViewById(R.id.tv_res);
            String resMsg = "回复消息：" + msg;
            tv_res.setText(resMsg);
        }


    }


    @Override
    public void onClick(View view) {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString("req_time", DateUtil.getNowTime());
        bundle.putString("req_content", msg);
        intent.putExtras(bundle);
        // 携带意图返回上一个页面
        setResult(Activity.RESULT_OK, intent);
        // 结束当前活动页面
        finish();
    }
}